{extend name="v1/layout/base"}
{block name="content"}
<div class="layuimini-main">
  <script type="text/html" id="toolbar">
    <div class="layui-btn-container">
      <button class="layui-btn layui-btn-black  layui-btn-sm" lay-event="reseve"><i class="layui-icon">&#xe63d;</i></button>
      <button class="layui-btn layui-btn-sm layui-btn-normal" lay-event="export"><i class="layui-icon">&#xe67d;</i>导出数据</button>
    </div>
  </script>

  <table class="layui-hide" id="currentTableId" lay-filter="currentTableFilter"></table>
</div>
{/block}
{block name="myScript"}
<script>
  layui.use(['form', 'table', 'laydate'], function() {
    var $ = layui.jquery,
      form = layui.form,
      laydate = layui.laydate,
      user_sn = '{$user_sn}',
      table = layui.table;
    table.render({
      elem: '#currentTableId',
      url: '/{:config("manage.manage_name")}/{:config("manage.version")}/User/userNextList',
      toolbar: '#toolbar',
      defaultToolbar: ['filter'],
      height: 'full-50',
      where: {
        user_sn: user_sn
      },
      cols: [
        [{
            field: 'develop',
            minWidth: '150',
            title: '代数'
          }, {
            field: 'user_name',
            minWidth: '150',
            title: '昵称'
          },
          {
            field: 'user_sn',
            minWidth: '100',
            title: '会员号'
          },
          {
            field: 'tel',
            minWidth: '150',
            title: '手机号'
          },
          {
            field: 'level_name',
            minWidth: '80',
            title: '等级'
          },
          {
            field: 'all_back_money',
            minWidth: '80',
            title: '总佣金'
          },
          {
            field: 'all_achievement_price',
            minWidth: '150',
            title: '团队总业绩'
          },
          {
            field: 'agent_achievement_price',
            minWidth: '150',
            title: '个人总业绩'
          },
          {
            field: 'purchases_order_price',
            minWidth: '150',
            title: '消费总金额'
          },
          {
            field: 'agent_time',
            minWidth: '200',
            title: '代理时间'
          },
          {
            field: 'bind_time',
            width: '200',
            title: '绑定时间'
          },
          {
            field: 'create_time',
            minWidth: '200',
            fixed: 'right',
            title: '注册'
          }
        ]
      ],
      limits: [100, 100, 150, 200, 250, 500, 1000],
      limit: 100,
      id: 'table_ids',
      page: true,
      skin: 'line'
    });

    // 顶部操作工具
    table.on('toolbar(currentTableFilter)', function(obj) {
      var url = $(this).attr('data-url');
      switch (obj.event) {
        case 'reseve':
          table.reload('table_ids');
          break;
        case 'export':
          var user_sn = '{$user_sn}';
          var url = "/{:config('manage.manage_name')}/{:config('manage.version')}/User/exportUserNextList";
          https(url, {user_sn: user_sn}, 'post', true, '正在导出会员数据').then(res => {
            if (res.result_code == 200) {
              var html = '<h1 style="padding: 0 20px;color:red;font-size:18px;margin-bottom:15px;">如果据量大于1万条系统自动分表导出</h1>';
              res.resultData.forEach(function(value, index) {
                html += '<h2 style="padding: 0 20px;font-size:16px;">第' + (index + 1) + '个订单文件：<a href="' + value + '">' + '下载' + '</a></h2>';
              })
              layer.open({
                type: 1,
                skin: 'layui-layer-rim', //加上边框
                area: ['400px', '400px'], //宽高
                content: html
              });
            }
          })
          break;
        case 'search':
          $("#xk-search-status").removeClass('xk-search-status');
          break;
      }
    })

  });
</script>
{/block}
